package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;

public class CSVLecturerDTO extends Object implements IsSerializable, ICSVDTO {

	private long id;
	private String name;
	private String surname;
	private String academicTitle;
	


    private boolean highlighted;
    
    public static final int SORT_CONST__ACADEMIC_TITLE = 0;
    public static final int SORT_CONST__NAME = 1;
    public static final int SORT_CONST__SURNAME = 2;
    public static final int SORT_CONST__ID = 3;

	

    
	public CSVLecturerDTO() {}

	
	
	public CSVLecturerDTO(long id, String name, String surname, String academicTitle) {
		super();
		this.id = id;
		this.name = name;
		this.surname = surname;
		this.academicTitle = academicTitle;
	}




	public String getName() {
		return name;
	}




	public void setName(String name) {
		this.name = name;
	}




	public String getSurname() {
		return surname;
	}




	public void setSurname(String surname) {
		this.surname = surname;
	}




	public String getAcademicTitle() {
		return academicTitle;
	}




	public void setAcademicTitle(String academicTitle) {
		this.academicTitle = academicTitle;
	}




	public String toString() {
		String result = "" +
			"[ " + CSVLecturerDTO.class + "]" +
			"name: " + name + 
			", surname: " + surname +
			", academicTitle: " + academicTitle
			;
		return result;
	}
	
	public String toLabel() {
		String r = surname + " " + name + ", " + academicTitle;
		return r;
	}

	
	
	public String toLabelShort() {
		String r = surname;
		return r;
	}

	public String toLabelLong() {
		String r = academicTitle + " " + name + " " + surname;
		return r;
	}


	public long getId() {
		return id;
	}



	public void setId(long id) {
		this.id = id;
	}
	
	
	
	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__ACADEMIC_TITLE) {
			return "" + getAcademicTitle();
		} else if (col == SORT_CONST__NAME) {
			return "" + getName();
		} else if (col == SORT_CONST__SURNAME) {
			return "" + getSurname();
		}
		return "no field";
	}

	
	@SuppressWarnings("unchecked")
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

//			    final int BEFORE = -1;
			    final int EQUAL = 0;
//			    final int AFTER = 1;
			    
			    CSVLecturerDTO obj1;
			    CSVLecturerDTO obj2;
			    if (o1 instanceof CSVLecturerDTO && o2 instanceof CSVLecturerDTO) {

					obj1 = (CSVLecturerDTO) o1;
					obj2 = (CSVLecturerDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__ACADEMIC_TITLE) {
						return obj1.getAcademicTitle().compareTo(obj2.getAcademicTitle());
					} else if (colIndex == SORT_CONST__NAME) {
						return obj1.getName().compareTo(obj2.getName());
					} else if (colIndex == SORT_CONST__SURNAME) {
						return obj1.getSurname().compareTo(obj2.getSurname());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}

	
	
	
	

	public boolean isHighlighted() {
		return highlighted;
	}



	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}
	
	
	
}
